/**
 * @author spooky
 */
 
import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.layout.Resizable;
import javafx.scene.layout.HBox;
import javafx.scene.Group;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;




public class MyMediaPlayer extends CustomNode, Resizable {

	public var movieWidth:Number;
	public var movieHeight:Number;

	var media: Media;
	
	var videoSrc:String on replace old {
	    media = Media {
	        source: videoSrc
	    }
	    //media.source = videoSrc
	}
	
	/*var media = Media{
	    source: bind videoSrc
	};*/
	
	var player = MediaPlayer{
	    media: bind media;
	    autoPlay:true
	};
	
	var mediaView:MediaView = MediaView {
        visible: true
        preserveRatio: true
    	mediaPlayer: bind player
    	fitHeight: bind movieHeight
    	fitWidth: bind movieWidth
	}
	
	
	/**
	 * Create the Node
	 */
	public override function create():Node {
		return Group{
			content: [mediaView]
		}
	}
	
	public function play() {
	    player.play()
	}
	
	public function setVideo(pVideoSrc:String) {
	    videoSrc = pVideoSrc;
	    println("Setting Video to: {pVideoSrc}");
	    println(media.source);
	    player.play();
	}
	
	
	public override function getPrefHeight(height):Number {
		height
	}
	
	public override function getPrefWidth(width):Number {width
	}	
}